//
//  EFSelectTableMenuCell.m
//  change
//
//  Created by 苏友龙 on 16/11/18.
//  Copyright © 2016年 Pulian. All rights reserved.
//

#import "EFSelectTableMenuCell.h"
#import "Masonry.h"
#import "Constant.h"

#ifdef NEED_FRAMEWORK
#import <IOSESPBaseFramework/FileUtil.h>
#else
#import "FileUtil.h"
#endif
#import "EnvironmentVariable.h"
#import "ThemeKit.h"

@implementation EFSelectTableMenuCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
        [self createTheme];
    }
    return self;
}

-(void)createTheme {
    self.theme_backgroundColor = self.contentView.theme_backgroundColor = [UIColor theme_colorForKey:@"cellBackgroud" ];
    self.title.theme_textColor = [UIColor theme_colorForKey:@"cellTitle" ];
}

- (void)createViews{
    self.titleImage = [[UIImageView alloc] init];
    [self addSubview:self.titleImage];
    
    self.title = [[UILabel alloc] init];
    self.title.font = [UIFont systemFontOfSize:18.0];
    [self addSubview:self.title];
    
    self.addOrRemove = [UIButton buttonWithType:UIButtonTypeCustom];
    self.addOrRemove.layer.cornerRadius = 8;
    self.addOrRemove.layer.borderWidth = 2;
    self.addOrRemove.layer.borderColor = [UIColor colorWithRed:67/255.0 green:137/255.0 blue:233/255.0 alpha:1].CGColor;
    self.addOrRemove.layer.borderColor = EF_OLD_RED_COLOR.CGColor;
    self.addOrRemove.layer.masksToBounds = YES;
    [self.addOrRemove addTarget:self action:@selector(ClickaddOrRemoveBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.addOrRemove];
    
    //    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 59.50f, CGRectGetMaxX(self.bounds), 0.5f)];
    //    line2.backgroundColor = [UIColor lightGrayColor];
    //    line2.alpha = 0.5f;
    //    [self addSubview:line2];
    
    [self.titleImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(20);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@50);
        make.height.equalTo(@50);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleImage.mas_right).with.offset(20);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@150);
        make.height.equalTo(@35);
    }];
    
    [self.addOrRemove mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-10);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@60);
        make.height.equalTo(@35);
    }];
    
}

- (void)titleImagePath:(NSString *)str{
    if(![str isEqualToString:@""]){
        NSString *path = [[EnvironmentVariable getVersionPath] stringByAppendingString:@"/Image"];
        self.titleImage.image = [[UIImage alloc]initWithData:[FileUtil getFileDataWithPath:str andTypePath:path]];
    }
}

- (void)ClickaddOrRemoveBtn{
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(clickAddOrRemoveButton:)]) {
        [self.delegate clickAddOrRemoveButton:self];
    }
}

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
